//
//  EditSexViewController.m
//  WeightMaster
//
//  Created by maoyu on 15/8/18.
//  Copyright (c) 2015年 buddysoft. All rights reserved.
//

#import "EditGenderViewController.h"
#import "BDFoundation.h"
#import "UIColor+WeightMaster.h"
#import "WMAppSetting.h"

#define GRAY_COLOR  RGB(135,135,135)

@interface EditGenderViewController ()

@end

@implementation EditGenderViewController

#pragma 私有函数
- (void)initView {
    [self.femaleButton layoutIfNeeded];
    [self.maleButton layoutIfNeeded];
    
    [self.femaleButton makeCircleWithBorderColor:[UIColor mainColor] withWidth:1.0];
    [self.maleButton makeCircleWithBorderColor:[UIColor mainColor] withWidth:1.0];
    
    [self.nextButton makeCornorRadius:17.0];
}

#pragma 事件函数
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择您的性别";
    
    [self initView];
    
    if ([WMAppSetting sharedInstance].gender) {
        if (WMGenderMale == [[WMAppSetting sharedInstance].gender integerValue]) {
            [self male:nil];
        }else {
            [self female:nil];
        }
    }else {
        [self female:nil];
    }
    
    if (self.editMode) {
        [self.nextButton setTitle:@"保存" forState:UIControlStateNormal];
    }
    
    // push的界面只显示返回按键
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)female:(id)sender {
    self.femaleButton.alpha = 1.0;
    [self.femaleButton addBorderWithWidth:1 withColor:[UIColor mainColor]];
    
    self.maleButton.alpha = .5;
    [self.maleButton addBorderWithWidth:1 withColor:GRAY_COLOR];
    
    [WMAppSetting sharedInstance].gender = [NSNumber numberWithInteger:WMGenderFemale];
}

- (IBAction)male:(id)sender {
    self.maleButton.alpha = 1.0;
    [self.maleButton addBorderWithWidth:1 withColor:[UIColor mainColor]];
    
    self.femaleButton.alpha = .5;
    [self.femaleButton addBorderWithWidth:1 withColor:GRAY_COLOR];
    
    [WMAppSetting sharedInstance].gender = [NSNumber numberWithInteger:WMGenderMale];
}

- (IBAction)next:(id)sender {
    
    if (self.editMode) {
        [[WMAppSetting sharedInstance] syncData];
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self performSegueWithIdentifier:@"ToEditHeight" sender:self];        
    }
}

@end
